import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex);

export default new Vuex.Store({
    debug: true,
    state: {
        userPrivilege: [],
        user: null,
        webSocketId: null,
        userId: null
    },
    mutations: {
        setUserPrivilege(state, privileges) {
            state.userPrivilege = privileges;
        },
        setUser(state, user) {
            state.user = user
        },
        setWebSocketId(state, webSocketId) {
            state.webSocketId = webSocketId
        },
        setUserId(state, userId) {
            state.userId = userId
        },
        removeUser(state) {
            state.user = null;
            state.userId = null;
            state.webSocketId = null;
            state.userPrivilege = [];
        }
    },
    plugins: [createPersistedState({
        storage: window.sessionStorage
    })]

})